clear all

***set working directory***
cd "..."
version 15


set maxvar 30000



** import Raw_Data on STATA using the "ztree2stata" package as provided by Kan Takeuchi, Graduate School of Economics, Hitotsubashi University, Japan.


ztree2stata subjects using 211116_1309.xls 
replace treatment = 0
keep if Period > 0
drop TimeOKStage0OK TimeStage1OpenFirstOK TimeStage2MoveOK TimeUEStage3OK TimeStage3OK TimeUEStage4OK TimeStage4OK TimeOKFinalStageOK finalchoice tables
drop Group Profit TotalProfit Participate roundprofits paid_period1 paid_period2 paid_period3 paid_period4 paid_period5 payoff1 payoff2
save "T0_A.dta", replace
clear all

ztree2stata subjects using 211116_1426.xls
replace treatment = 1
keep if Period > 0
drop TimeOKStage0OK TimeStage1OpenFirstOK TimeStage2MoveOK TimeUEStage3OK TimeStage3OK TimeUEStage4OK TimeStage4OK TimeOKFinalStageOK finalchoice tables
drop Group Profit TotalProfit Participate roundprofits paid_period1 paid_period2 paid_period3 paid_period4 paid_period5 payoff1 payoff2
save "T1_A.dta", replace
clear all

ztree2stata subjects using 211129_0941.xls
replace treatment = 3
gen Session = 2
keep if Period > 0
drop TimeOKStage0OK TimeStage1OpenFirstOK TimeStage2MoveOK TimeUEStage3OK TimeStage3OK TimeUEStage4OK TimeStage4OK TimeOKFinalStageOK finalchoice tables
drop Group Profit TotalProfit Participate roundprofits paid_period1 paid_period2 paid_period3 paid_period4 paid_period5 payoff1 payoff2
save "T2_A.dta", replace
clear all


ztree2stata subjects using 211129_1135.xls
replace treatment = 2
keep if Period > 0
drop TimeOKStage0OK TimeStage1OpenFirstOK TimeStage2MoveOK TimeUEStage3OK TimeStage3OK TimeUEStage4OK TimeStage4OK TimeOKFinalStageOK
finalchoice tables
drop Group Profit TotalProfit Participate roundprofits paid_period1 paid_period2 paid_period3 paid_period4 paid_period5 payoff1 payoff2
save "T3_A.dta", replace
clear all



use "T0_A.dta", clear
append using "T1_A.dta"
append using "T2_A.dta"
append using "T3_A.dta"
** Add labels
label variable openfirst "Safe box first"
label variable pos2      "Potential Content of safe Box"
label variable box1      "Content of Risky box"
label variable box2      "Content of Safe box"   
label variable Subject   "Subjects 1-10"
label variable Period    "Rounds 1-100"   
label variable take1oropen2 "Subject's choices"   
label variable take2oropen1 "Subject's choices" 
label variable treatment     "0=w50,  1=w90, 2=d50, 3=d90" 
label variable Payoff   "Subject's Payoff per round"
label variable session "Session date"
** Generate Identifier based on Session, treatment and Subject
egen ID2 = group(session treatment Subject)
label variable ID2 "Identifier based on Session, treatment and Subject"
** Generate interaction term treatment * Potential Content of Box2
gen inter = treatment * pos2
label variable inter "treatment * potential content of safe box"
** openfirst (i.e. safeboxfirst) = 1 if safe box is opened and =0 if risky box is opened.
replace openfirst = openfirst - 1
** Success rate based on 1st move
gen correct1_r0 = 0
label variable correct1_r0 "Success rate based on 1st move"
replace correct1_r0 = 1 if openfirst == 0 & treatment == 0
replace correct1_r0 = 1 if openfirst == 1 & treatment == 1
replace correct1_r0 = 1 if openfirst == 0 & treatment == 2
replace correct1_r0 = 1 if openfirst == 0 & treatment == 3
gen     Treat = 0 if treatment==0 | treatment==1
replace Treat = 1 if treatment==2 | treatment==3
label variable Treat "=0 if Treatments 0,1    =1 if Treatments 2,3"
order ID2 Session session treatment Subject openfirst box1 box2 pos2 Payoff inter correct1_r0
save Additional.dta, replace